<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录页面</title>
    <style>
        body {
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
            background-color: #f5f5f7;
            color: #1d1d1f;
            margin: 0;
            padding: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
        }
        #app {
            width: 100%;
            max-width: 400px;
            padding: 20px;
            background-color: #fff;
            border-radius: 10px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
            text-align: center;
        }
        h1 {
            font-size: 24px;
            margin-bottom: 20px;
            color: #007aff;
        }
        input[type="text"],
        input[type="password"] {
            width: 100%;
            padding: 10px;
            margin-bottom: 10px;
            border: 1px solid #ddd;
            border-radius: 5px;
            background-color: #f9f9f9;
            font-size: 16px;
            color: #333;
        }
        input[type="button"] {
            width: 100%;
            padding: 10px;
            background-color: #007aff;
            border: none;
            border-radius: 5px;
            color: #fff;
            font-size: 16px;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }
        input[type="button"]:hover {
            background-color: #0062cc;
        }
    </style>
</head>
<body>

<div id="app">
    <h1>登录页面</h1>
    <input type="text" placeholder="用户名" v-model="user.username">
    <input type="password" placeholder="密码" v-model="user.password">
    <input type="button" value="登录" @click="login()">
</div>

<!-- 引入axios和vue的框架文件 -->
<script src="https://cdn.bootcss.com/axios/0.18.0/axios.min.js"></script>
<script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
<script>
    let v = new Vue({
        el: "#app",
        data: {
            user: { username: "", password: "" }
        },
        methods: {
            login() {
                axios.post("/v1/users/login", v.user).then(function (response) {
                    if (response.data == 1) {
                        alert("登录成功");
                        location.href = "/";
                    } else if (response.data == 2) {
                        alert("密码错误");
                    } else {
                        alert("用户名不存在");
                    }
                });
            }
        }
    });
</script>

</body>
</html>
